import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        while (n > 0) {
            n--;
            int len = scanner.nextInt() * 2;
            String str = scanner.next();
            //构造ABABABAB...
            char[] ch1 = new char[len];
            for (int i = 0; i < len; i++) {
                ch1[i] = (i % 2 == 0 ? 'A' : 'B');
            }
            //构造BABABABA...
            char[] ch2 = new char[len];
            for (int i = 0; i < len; i++) {
                ch2[i] = (i % 2 == 0 ? 'A' : 'B');
            }
            int count1 = 0, count2 = 0;
            for (int i = 0; i < len; i++) {
                if (str.charAt(i) != ch1[i]) {
                    count1++;
                } else {
                    count2++;
                }
            }
            System.out.println(Math.min(count1 / 2, count2 / 2));
        }

        scanner.close();
    }
}
